package com.ztesoft.report.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ztesoft.report.base.pojo.R;
import com.ztesoft.report.base.service.impl.BaseServiceImpl;
import com.ztesoft.report.dao.ServiceInterfaceDao;
import com.ztesoft.report.entity.ServiceInterface;
import com.ztesoft.report.service.ServiceInterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务接口表 服务实现类
 * </p>
 *
 * @author y3tu
 * @since 2018-06-21
 */
@Service
public class ServiceInterfaceServiceImpl extends BaseServiceImpl<ServiceInterfaceDao, ServiceInterface> implements ServiceInterfaceService {
    @Autowired
    ServiceInterfaceDao serviceInterfaceDao;
    @Autowired
    ReportCategoryServiceImpl reportCategoryService;

    @Override
    public Map getServiceInterfaceList(Map<String, Object> param) {
        int size = (int) param.get("size");
        int current = (int) param.get("current");
        PageHelper.startPage(current, size);
        List<ServiceInterface> list = null;
        if (param.get("categoryId") != null && !"".equals(param.get("categoryId"))) {
            List<Integer> ids = reportCategoryService.getAllChildId((Integer) param.get("categoryId"));
            param.put("categoryId", ids);
        } else {
            param.remove("categoryId");
        }
        list = serviceInterfaceDao.getServiceInterfaceList(param);
        PageInfo<ServiceInterface> page = new PageInfo<>(list);
        return R.ok(page);
    }

    @Override
    public void updateServiceInterface(ServiceInterface serviceInterface) {
        serviceInterfaceDao.updateServiceInterface(serviceInterface);
    }
}
